#!/usr/bin/env python

import sys
#import pickle
import cPickle
    

class IO:
    


    
    def SaveFile(self, code, tape, filename):
        
        elementsOnTape =  len(tape[0])
        linesOfCode = len(code)
  
        
        SaveTape = []
        for t in range(0,elementsOnTape):
            SaveTape.append(tape[0][t])
            
        #tape er nu en 1d array og klar til at blive gemt
 
        
        
        SaveCode = []
        for i in range(linesOfCode):
            SaveCode.append([])
            for ii in range(6):
                SaveCode[i].append(code[i][ii])

        #code er nu 2d array og klar til at blive gemt
  
        FILE = open(filename, 'w')
        cPickle.dump((SaveCode, SaveTape), FILE)
        #cPickle.dump(SaveTape, FILE)
        FILE.close()


    def OpenFile(self, filename):
        FILE = open(filename, 'r')
        LoadCode, LoadTape = cPickle.load(FILE)
        FILE.close()
        
        return LoadCode, LoadTape


